<template>
    <div class="sidebar">
        <el-menu :default-active="onRoutes" class="el-menu-vertical-demo" unique-opened router>
            <template v-for="item in menu">
                <template v-if="item.subs">
                    <el-submenu :index="item.index">
                        <template slot="title"><i :class="item.icon"></i>{{ item.title }}</template>
                        <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index">{{ subItem.title }}
                        </el-menu-item>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index">
                        <i :class="item.icon"></i>{{ item.title }}
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
    import menu from 'config/menu';

    export default {
        data() {
            return {
                menu: menu
            }
        },
        computed:{
            onRoutes(){
                // let routeArr = this.$route.path.replace('/','').split('/');
                // return '/' + routeArr[0] + '/' + routeArr[1];
                // return this.$route.path;
                return '/' + this.$route.path.replace('/','');
            }
        }
    }
</script>

<style scoped>
    @import '../../static/css/icon.css';
    .sidebar{
        position: fixed;
        top: 70px;
        left: 0px;
        width: 250px;
        height: 100%;
        display: block;
        background: #2E363F;
    }
    .sidebar > ul {
        padding-top: 15px;
        height: 100%;
    }
    .el-menu-item {
        padding:0 70px !important;
        height: 48px;
        line-height: 48px;
    }
</style>
